﻿<script src="~/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.getColumnInfo.js"></script>

<div class="easyui-panel" data-options="fit:true,border:false">
    <table id="dg1"></table>
</div>

<script>
    $(function () {
        var getFrozenColumns = function () {
            var result = [];

            var c1 = [];
            c1.push({ field: 'ID', title: '主键', width: 100 });
            c1.push({ field: 'AreaName', title: '地区', width: 180 });
            c1.push({ field: 'Sex1', title: '男', width: 150 });
            c1.push({ field: 'Sex2', title: '女', width: 150 });

            result.push(c1);

            return result;
        };

        var getColumns = function () {
            var result = [];

            var normal00000 = [
                { field: 'TS1', title: '测试1', width: 160 },
                { field: 'TS2', title: '测试2', width: 160 },
                { field: 'TS3', title: '测试3', width: 160 },
                { field: 'TS4', title: '测试4', width: 160 },
                { field: 'TS5', title: '测试5', width: 160 }
            ];
            result.push(normal00000);

            return result;
        };
        var options = {
            title: "列表",
            idField: "ID",
            rownumbers: true,
            fit: true,
            border: false,
            singleSelect: true,
            toolbar: [
                {
                    iconCls: 'icon-add',
                    text: "获取冻结列集合",
                    handler: function () {
                        var columnFields = $("#dg1").datagrid("getColumnFields", true);
                        alert(JSON.stringify(columnFields));
                    }
                },
                "-",
                {
                    iconCls: 'icon-add',
                    text: "获取非冻结列集合",
                    handler: function () {
                        var columnFields = $("#dg1").datagrid("getColumnFields", false);
                        alert(JSON.stringify(columnFields));
                    }
                },
                "-",
                {
                    iconCls: 'icon-add',
                    text: "获取所有列集合",
                    handler: function () {
                        var columnFields = $("#dg1").datagrid("getColumnFields", "all");
                        alert(JSON.stringify(columnFields));
                    }
                },
                "-",
                {
                    iconCls: 'icon-add',
                    text: "获取所有列的options集合(F12查看控制台看输出结果)",
                    handler: function () {
                        var columnOptions = $("#dg1").datagrid("getColumnOptions", "all");
                        console.log(columnOptions);
                    }
                },
                "-",
                {
                    iconCls: 'icon-add',
                    text: "获取“男”列的下一个列option对象",
                    handler: function () {
                        var columnOption = $("#dg1").datagrid("getNextColumnOption", "Sex1");
                        alert(columnOption ? JSON.stringify(columnOption) : "未找到下一个列");
                    }
                },
                "-",
                {
                    iconCls: 'icon-add',
                    text: "获取“女”列的上一个列option对象",
                    handler: function () {
                        var columnOption = $("#dg1").datagrid("getPrevColumnOption", "Sex2");
                        alert(columnOption ? JSON.stringify(columnOption) : "未找到下一个列");
                    }
                }
            ],
            frozenColumns: getFrozenColumns(),
            columns: getColumns(),
            method: "get",
            url: "/Jsons/datagrid/datagrid-common-data.json"
        };

        $("#dg1").datagrid(options);
    });
</script>